define(function (require, exports, module) {
	var Grid = require("grid");
	var aw = require("ajaxwrapper");
	var fetchProperties = require("../constant/fetchProperties");
	var scatterCheckInBiz = require("../business/scatterCheckInBiz");
	var scatterCheckInSvc = require("../service/scatterCheckInSvc");
	var handler = require("../handler/ScatterCheckInHandler");
	
    var instance = {
        initComponent: function (params,widget) {
        	var component = new Grid({
                parentNode: ".J-grid", 
                autoRender:false,
                model : {
                    url : "api/checkinimplement/query",                    
                    params: function() {
                    	var subnav=widget.get("subnav");
                    	var registerStatus = subnav.getValue("registerStatus");
                        return {
                        	"nonMemGroupReserve.nonMemberGroup.statusIn":"Effective,Confirm,CheckIn",
                        	"servicePoint":subnav.getValue("servicePoint"),
                        	"nonMemGroupReserve.nonMemberGroup.checkInDate":subnav.getValue("dateRange").start,
     						"nonMemGroupReserve.nonMemberGroup.checkInDateEnd":subnav.getValue("dateRange").end,
     						"dataSourceIn":"NonMember,VisitDoorFIT",
     						"status":"Confirmed",
     						"StatementStatus":"NoStatement",
     						"nonMemGroupReserve.nonMemberGroup.isAbolished":false,
     						"orderString":"nonMemGroupReserve.nonMemberGroup.checkInDate",
     						fetchProperties: fetchProperties.fetchProperties
                        };
                    },
                    columns : [{
        				name:"servicePoint.name",
        				label:"目的地",
        				format: "detail",
        				formatparams: {
        					key: "detail",
        					handler: function(index,data,rowEle){
        						var form ={};
        						if(data.nonMemGroupReserve.nonMemberGroup.sourceType.key == "DropIn"){
        							widget.toCheckInDoor(data);
        							form= widget.get("doorForm");
        							form.setData(data.nonMemGroupReserve.nonMemberGroup);
        							form.setValue("servicePoint",data.nonMemGroupReserve.nonMemberGroup.servicePoint.name);
        							form.setReadonly("servicePoint",true);
        						}else{
        							widget.toCheckIn(data);
        							form= widget.get("form");
        						}
								handler.grid.handleAppointmentClick(widget,data);
								//widget.continueAdd = true;
								widget.get("selectRoom").hide();
								widget.get("formEnd").setDisabled(true);
								form.setReadonly("checkInDate",true);
								form.setReadonly("checkOutDate",true);
								widget.get("editgrid").setDisabled(true);
								$(".J-grid-editgrid-reset").hide();
								$(".J-grid-editgrid-delete").hide();
								widget.get("subnav").hide(["save"]);
								widget.detailClick = true;
        					}
        				}
        			},{
						name:"nonMemGroupReserve.nonMemberGroup.checkInDate",
						label:"入住日期",
						format:"date"
					},{
						name:"nonMemGroupReserve.nonMemberGroup.checkOutDate",
						label:"退房日期",
						format:"date"
					},{
						name:"nonMemGroupReserve.nonMemberGroup.perNumber",
        				label:"预订人数",
					},{
        				name:"signUpNumber",
        				label:"人数",
        				format:function(data, row){
        					var temp = [];
        	        		for(var i in row.roomPersonalInfos){
        	        			var roomPersonalInfos ={};
        	        			if(!row.roomPersonalInfos[i].nonMemberRegister.signUpRegister.exitGroup){
        	        				roomPersonalInfos = row.roomPersonalInfos[i];
        	        				temp.push(roomPersonalInfos);
        	        			}
        	        		}if(temp.length == 0){
        	        			return row.nonMemGroupReserve.nonMemberGroup.signUpNum;
        	        		}
        					return temp.length;
        				}
					},{						
						name:"nonMemGroupReserve.nonMemberGroup.contactName",
        				label:"联系人",
        				format:function(value, row){
        					if(!value){
        						if(row.roomPersonalInfos.length > 0){
        							return row.roomPersonalInfos[0].nonMemberRegister.signUpRegister.personalInfo.name;
        						}else{
        							return "";
        						}
        					}else{
        						return value;
        					}
        				}
					},{
        				name:"nonMemGroupReserve.nonMemberGroup.contactPhone",
        				label:"联系电话",
        				format:function(value, row){
        					if(!value){
        						if(row.roomPersonalInfos.length > 0){
        						
	        						var personal=row.roomPersonalInfos[0].nonMemberRegister.signUpRegister.personalInfo;
	        						if(personal.phone !=null){
	        							return personal.phone;
	        						}else if(personal.mobilePhone !=null){
	        							return personal.mobilePhone
	        						}else{
	        							return "";
	        						}
        						}else{
        							return "";
        						}
        					}else{
        						return value;
        					}
        				}
        			},{
						name:"nonMemberType",
						label:"散客类型",
						format:function(value, row){
							return scatterCheckInBiz.nonMenberStatus(row,"体验客户","预约散客团","预约个人","预约会员散客","上门散客团","上门个人","上门会员散客")
        				}
					},{
						name:"nonMemGroupReserve.nonMemberGroup.operateDate",
						label:"登记日期",
						format:"date"
					},{
        				name:"registerStatus",
        				label:"状态",
        				format:function(value, row){
        					return value.value;        					
        				}
        			},{
						name:"operate",
						label:"操作",
						format:"button",
						formatparams:[{
							id:"appointment",
							text: "入住登记",
							show:function(value,row){		
								if(scatterCheckInBiz.nonMenberStatus(row,true,true,true,true,false,false,false)){
									return	scatterCheckInBiz.checkInStatus(row,true,false);
								}else{
									return false;
								}
								
							},
							handler:function(index,data,rowEle){
								widget.toCheckIn(data);
								handler.grid.handleAppointmentClick(widget,data);
							}
						},{
							id:"edit",
							text: "修改",
							show:function(value,row){
								if(scatterCheckInBiz.nonMenberStatus(row,false,false,false,false,true,true,true,true)){
									return scatterCheckInBiz.checkInStatus(row,true,false);
								}else{ 
									return false;
								}
								
							},
							handler:function(index,data,rowEle){
								widget.toCheckIn(data);
								handler.grid.handleAppointmentClick(widget,data);
							}
						},{
							id:"continue",
							text: "续住",
							show:function(value,row){
								return scatterCheckInBiz.checkInStatus(row,false,true);
							},
							handler:function(index,data,rowEle){
								widget.set("continueData",data);
								if(data.nonMemGroupReserve.nonMemberGroup.sourceType.key == "DropIn"){
									widget.toCheckInDoor(data);
								}else{
									widget.toCheckIn(data);
								}
								handler.grid.handleAppointmentClick(widget,data);
								widget.continueAdd = true;
								widget.get("selectRoom").hide();
								widget.get("formEnd").setDisabled(true);
								widget.get("form").setReadonly("checkInDate",true);
								widget.get("editgrid").setDisabled(true);
								$(".J-grid-editgrid-reset").hide();
								$(".J-grid-editgrid-delete").hide();
								
							}
						}]
					}]
                }
            });
            widget.set("grid",component);
        }
    };
    module.exports = instance;
});